package o;

import android.text.TextUtils;
import com.google.android.exoplayer2.text.webvtt.WebvttCssStyle;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

final class akj {
    private static final Pattern ॱ = Pattern.compile("\\[voice=\"([^\"]*)\"\\]");
    private final StringBuilder ˎ = new StringBuilder();
    private final anc ˏ = new anc();

    public WebvttCssStyle ˋ(anc o_anc) {
        this.ˎ.setLength(0);
        int ˋ = o_anc.ˋ();
        ˎ(o_anc);
        this.ˏ.ॱ(o_anc.ˏ, o_anc.ˋ());
        this.ˏ.ˋ(ˋ);
        String ˎ = ˎ(this.ˏ, this.ˎ);
        if (ˎ == null || !"{".equals(ˋ(this.ˏ, this.ˎ))) {
            return null;
        }
        WebvttCssStyle webvttCssStyle = new WebvttCssStyle();
        ˋ(webvttCssStyle, ˎ);
        int i = 0;
        Object obj = null;
        while (i == 0) {
            int ˋ2 = this.ˏ.ˋ();
            obj = ˋ(this.ˏ, this.ˎ);
            if (obj == null || "}".equals(obj)) {
                i = 1;
            } else {
                i = 0;
            }
            if (i == 0) {
                this.ˏ.ˋ(ˋ2);
                ˊ(this.ˏ, webvttCssStyle, this.ˎ);
            }
        }
        return !"}".equals(obj) ? null : webvttCssStyle;
    }

    private static String ˎ(anc o_anc, StringBuilder stringBuilder) {
        ॱ(o_anc);
        if (o_anc.ˊ() < 5) {
            return null;
        }
        if (!"::cue".equals(o_anc.ˊ(5))) {
            return null;
        }
        int ˋ = o_anc.ˋ();
        String ˋ2 = ˋ(o_anc, stringBuilder);
        if (ˋ2 == null) {
            return null;
        }
        if ("{".equals(ˋ2)) {
            o_anc.ˋ(ˋ);
            return "";
        }
        String ˊ;
        if ("(".equals(ˋ2)) {
            ˊ = ˊ(o_anc);
        } else {
            ˊ = null;
        }
        ˋ2 = ˋ(o_anc, stringBuilder);
        if (!")".equals(ˋ2) || ˋ2 == null) {
            return null;
        }
        return ˊ;
    }

    private static String ˊ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        int i = ˋ;
        Object obj = null;
        while (i < ॱ && r0 == null) {
            int i2 = i + 1;
            if (((char) o_anc.ˏ[i]) == ')') {
                obj = 1;
            } else {
                obj = null;
            }
            i = i2;
        }
        return o_anc.ˊ((i - 1) - o_anc.ˋ()).trim();
    }

    private static void ˊ(anc o_anc, WebvttCssStyle webvttCssStyle, StringBuilder stringBuilder) {
        ॱ(o_anc);
        String ˊ = ˊ(o_anc, stringBuilder);
        if (!"".equals(ˊ) && ":".equals(ˋ(o_anc, stringBuilder))) {
            ॱ(o_anc);
            String ˏ = ˏ(o_anc, stringBuilder);
            if (ˏ != null && !"".equals(ˏ)) {
                int ˋ = o_anc.ˋ();
                String ˋ2 = ˋ(o_anc, stringBuilder);
                if (!";".equals(ˋ2)) {
                    if ("}".equals(ˋ2)) {
                        o_anc.ˋ(ˋ);
                    } else {
                        return;
                    }
                }
                if ("color".equals(ˊ)) {
                    webvttCssStyle.ˎ(amt.ˏ(ˏ));
                } else if ("background-color".equals(ˊ)) {
                    webvttCssStyle.ॱ(amt.ˏ(ˏ));
                } else if ("text-decoration".equals(ˊ)) {
                    if ("underline".equals(ˏ)) {
                        webvttCssStyle.ˊ(true);
                    }
                } else if ("font-family".equals(ˊ)) {
                    webvttCssStyle.ˎ(ˏ);
                } else if ("font-weight".equals(ˊ)) {
                    if ("bold".equals(ˏ)) {
                        webvttCssStyle.ˏ(true);
                    }
                } else if ("font-style".equals(ˊ) && "italic".equals(ˏ)) {
                    webvttCssStyle.ॱ(true);
                }
            }
        }
    }

    static void ॱ(anc o_anc) {
        Object obj = 1;
        while (o_anc.ˊ() > 0 && r0 != null) {
            obj = (ˏ(o_anc) || ॱॱ(o_anc)) ? 1 : null;
        }
    }

    static String ˋ(anc o_anc, StringBuilder stringBuilder) {
        ॱ(o_anc);
        if (o_anc.ˊ() == 0) {
            return null;
        }
        String ˊ = ˊ(o_anc, stringBuilder);
        return "".equals(ˊ) ? "" + ((char) o_anc.ʽ()) : ˊ;
    }

    private static boolean ˏ(anc o_anc) {
        switch (ˊ(o_anc, o_anc.ˋ())) {
            case '\t':
            case '\n':
            case '\f':
            case '\r':
            case ' ':
                o_anc.ˎ(1);
                return true;
            default:
                return false;
        }
    }

    static void ˎ(anc o_anc) {
        do {
        } while (!TextUtils.isEmpty(o_anc.ˊˋ()));
    }

    private static char ˊ(anc o_anc, int i) {
        return (char) o_anc.ˏ[i];
    }

    private static String ˏ(anc o_anc, StringBuilder stringBuilder) {
        StringBuilder stringBuilder2 = new StringBuilder();
        Object obj = null;
        while (obj == null) {
            int ˋ = o_anc.ˋ();
            String ˋ2 = ˋ(o_anc, stringBuilder);
            if (ˋ2 == null) {
                return null;
            }
            if ("}".equals(ˋ2) || ";".equals(ˋ2)) {
                o_anc.ˋ(ˋ);
                obj = 1;
            } else {
                stringBuilder2.append(ˋ2);
            }
        }
        return stringBuilder2.toString();
    }

    private static boolean ॱॱ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        byte[] bArr = o_anc.ˏ;
        if (ˋ + 2 <= ॱ) {
            int i = ˋ + 1;
            if (bArr[ˋ] == (byte) 47) {
                ˋ = i + 1;
                if (bArr[i] == (byte) 42) {
                    i = ˋ;
                    while (i + 1 < ॱ) {
                        ˋ = i + 1;
                        if (((char) bArr[i]) == '*' && ((char) bArr[ˋ]) == '/') {
                            ॱ = ˋ + 1;
                            ˋ = ॱ;
                        }
                        i = ˋ;
                    }
                    o_anc.ˎ(ॱ - o_anc.ˋ());
                    return true;
                }
            }
        }
        return false;
    }

    private static String ˊ(anc o_anc, StringBuilder stringBuilder) {
        int i = 0;
        stringBuilder.setLength(0);
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        while (ˋ < ॱ && r0 == 0) {
            char c = (char) o_anc.ˏ[ˋ];
            if ((c < 'A' || c > 'Z') && ((c < 'a' || c > 'z') && !((c >= '0' && c <= '9') || c == '#' || c == '-' || c == '.' || c == '_'))) {
                i = 1;
            } else {
                ˋ++;
                stringBuilder.append(c);
            }
        }
        o_anc.ˎ(ˋ - o_anc.ˋ());
        return stringBuilder.toString();
    }

    private void ˋ(WebvttCssStyle webvttCssStyle, String str) {
        if (!"".equals(str)) {
            int indexOf = str.indexOf(91);
            if (indexOf != -1) {
                Matcher matcher = ॱ.matcher(str.substring(indexOf));
                if (matcher.matches()) {
                    webvttCssStyle.ॱ(matcher.group(1));
                }
                str = str.substring(0, indexOf);
            }
            String[] ˎ = anr.ˎ(str, "\\.");
            String str2 = ˎ[0];
            int indexOf2 = str2.indexOf(35);
            if (indexOf2 != -1) {
                webvttCssStyle.ˊ(str2.substring(0, indexOf2));
                webvttCssStyle.ˏ(str2.substring(indexOf2 + 1));
            } else {
                webvttCssStyle.ˊ(str2);
            }
            if (ˎ.length > 1) {
                webvttCssStyle.ˋ((String[]) Arrays.copyOfRange(ˎ, 1, ˎ.length));
            }
        }
    }
}
